//
//  YZClient+RechargeDraw.m
//  YZMicroStock
//
//  Created by Lv.Dongdong on 16/4/13.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZClient+RechargeDraw.h"
#import "YZMFastPayViewController.h"

#define payLianlian @"pay_lianlian"
#define payLiandong @"pay_liandong"
#define payAiBei    @"pay_iapppay"
#define payZFB   @"pay_zhifubao"
#define payHeFuBao  @"pay_hfbpay"

@implementation YZNetworkManager (RechargeDraw)

- (void)fetchFundListWithType:(YZS_FUND_TYPE)type andPage:(NSInteger)page andPageSize:(NSInteger)pageSize andTimeEnd:(NSString *)timeEnd
                      success:(void (^)(NSURLResponse *task,id responseObject))success
                      failure:(void (^)(NSError *error))failure {

    NSString *fundType = nil;
    NSString *explain = nil;
    NSString *URLStr = URL_FOR_FETCH_FUND_LIST;
    
    switch (type) {
        case YZS_FUND_TYPE_FOR_ALL:
            fundType = @"all";
            explain = @"all";
            URLStr = URL_FOR_FETCH_FUND_ALL;
            break;
        case YZS_FUND_TYPE_FOR_RECHARGE:
            fundType = @"chargeWithdraw";
            explain = @"income";
            break;
        case YZS_FUND_TYPE_FOR_WITHDRAW:
            fundType = @"chargeWithdraw";
            explain = @"outcome";
            break;
        case YZS_FUND_TYPE_FOR_INCOME:
            fundType = @"loan";
            explain = @"income";
            break;
        case YZS_FUND_TYPE_FOR_OUTCOME:
            fundType = @"loan";
            explain = @"outcome";
            break;
        default:
            break;
    }
    
    NSDictionary *params = @{@"action": fundType, @"timeStart": timeEnd, @"explain": explain, @"page": @(page), @"pageSize": @(pageSize), @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URLStr parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task.response, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)rd_fetchRechargeURLWithMoney:(NSString *)money payMethod:(NSString *)payMethod success:(void (^)(NSURLResponse *task,id responseObject))success
                          failure:(void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"money":money, COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    NSString *urlString = URL_FOR_FETCH_RECHARGE_URL;//默认联动
    if ([payMethod isEqualToString:payLianlian]) {
        urlString =  URL_FOR_FETCH_LIANLIAN_URL;
        //
    }else if([payMethod isEqualToString:payAiBei]){
        urlString = URL_FOR_FETCH_AIBEI_URL;
    }else if ([payMethod isEqualToString:payHeFuBao]){
        urlString = URL_FOR_FETCH_HEFUBAO_URL;
    }
    [self.mainNetwork cq_noCachePOST: urlString parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task.response, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)rd_fetchRechargeResultWithBillNo:(NSString *)billNo success:(void (^)(NSURLResponse *task, id responseObject))success failure:(void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"payNumber":billNo, COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_RECHARGE_RESULT parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task.response, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)checkPayMethodCountWithSuccess:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params = @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCacheGET:URL_FOR_CHECK_PayMETHODCOUNT parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    } ];
    
}

- (void)rd_fetchRechargeTokenWithBankCode:(NSString *)bankCode andBankCard:(NSString *)bankCard andAmount:(double)amount andCharge:(double)charge success:(void (^)(NSURLResponse *task,id responseObject))success failure:(void (^)(NSError *error))failure{
    
    NSMutableDictionary *params = [@{@"money":@(amount), @"charge":@(charge), COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} mutableCopy];
    if (bankCard.length != 0) {
        [params setObject:bankCard forKey:@"bankCard"];
        [params setObject:bankCode forKey:@"bankCode"];
    }
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_RECHARGE_TOKEN_FIRST_TIME parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task.response, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)rd_fetchRechargeTokenWithBankCardID:(long long)bankCardID andAmount:(double)amount andCharge:(double)charge success:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    NSMutableDictionary *params = [@{@"cardId":@(bankCardID), @"money":@(amount),@"charge":@(charge), COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} mutableCopy];
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_RECHARGE_TOKEN parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task.response, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)rd_submitDrawRequestWithBankCardID:(long long)cardID andMoney:(NSString *)money andDrawPassword:(NSString *)drawPassword success:(void (^)(NSURLResponse *task,id responseObject))success failure:(void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"cardId":@(cardID), @"password":drawPassword, @"money":money,COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_SUBMIT_DRAW parameters: params
                             success:^(NSURLSessionDataTask *operation, id resObj) {
                                 if (success) {
                                     
                                     success(operation.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)rd_payRequestWithMoney:(NSString *)money andAccount:(NSString *)account success:(void (^)(NSURLResponse *task, id responseObject))success failure:(void (^)(NSError *error))failure{
    
    NSDictionary *params = @{@"money":money, @"payZFName":account, COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE, @"charge":@"0"};
    
    [self.mainNetwork cq_noCachePOST: [NSString stringWithFormat:@"pay/alip%@",@"ay.json"] parameters: params
                             success:^(NSURLSessionDataTask *operation, id resObj) {
                                 if (success) {
                                     
                                     success(operation.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)cancelWithDrawWithID:(NSInteger)ID success:(void (^)(NSURLResponse *task,id responseObject))success failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"id":@(ID), COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_CANCEL_WITHDRAW parameters: params
                             success:^(NSURLSessionDataTask *operation, id resObj) {
                                 if (success) {
                                     
                                     success(operation.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)freezemoney_success:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    NSDictionary *params = @{ COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
//    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_FREEZE_MONEY_DATA parameters: params
//                             success:^(NSURLSessionDataTask *operation, id resObj) {
//                                 if (success) {
//                                     
//                                     success(operation.response, resObj);
//                                 }
//                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
//                                 if (failure) {
//                                     failure(error);
//                                 }
//                             }];
    [self.mainNetwork cq_noCacheGET: URL_FOR_FETCH_FREEZE_MONEY_DATA parameters: params
                            success:^(NSURLSessionDataTask *task, id resObj) {
                                if (success) {
                                    
                                    success(task.response, resObj);
                                }
                            } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];
}
@end
